<<<<<<< .mine
# This program helps the Owner of a coffe shop to know when to buy coffee beans

import urllib.request #import the urllib module in order to access the internet
import time #the time module allows the use functionality such as minutes and seconds in functions

def get_price():
    page = urllib.request.urlopen("http://beans.itcarlow.ie/prices-loyalty.html") #This contains the url in which the current price of beans is specified on the internet.
    text = page.read().decode("utf8")

    #This locates the place in the line range where the "$" sign is.
    where = text.find(">$")

    # the specifies a location in the string in "page" variable that is 3 places after after the "$" sign.
    start_price = where + 2 
    end_price = where + 6 # The end_price specifies a location in the string in the "page" variable that is 7-places after the $ sign.
    price_time = time.asctime(time.localtime(time.time()))  #!!! In this particular case, the time posted on the website of the beans price is more desirable than the local time.
    return price_time, float(text[start_price:end_price])# the function returns a range that is used to specify the data to be captured the price which is between start_price and end_price.



price_now = input("Do you require current price (Y/N): ")#The input statement takes a comment from the user if he wants the program to retrieve the current price from the url

if price_now == "Y": # booleen condition is true i.e if the user wants the current price, then the next piece of code will run
    print(get_price())#the program will execute the "get_price" function to retrieve the current price from the url
else:
    price = 95.5
    while price > 4.74: #otherwise if the user wants to wait for the price to fall below 4.74
        time.sleep(900) #then in every fifteen minutes
        get_price() # the program will run the get_price function to check if price is below the price

        print("Buy") #then the program will buy more beans
=======
import urllib.request
import time
def get_price():
    page = urllib.request.urlopen("http://beans.itcarlow.ie/prices-loyalty.html")
    text = page.read().decode("utf8")
    where = text.find(">$")
    start_price = where + 2
    end_price = where + 6
    return float(text[start_price:end_price])  #how about also returning the validity (date and time) of this price?

buy_beans = input("Do you require current price (Y/N): ")
if buy_beans == "Y":
    print(get_price())
else:
    buy_mark = 95.5
    while buy_mark > 4.74:
        time.sleep(900)
        get_price()
        print("Buy")
